﻿<!-- #include file="ding.asp" -->
<!-- #include file="mymin.asp" -->
<%
Call Head2
%>
<title>数据库备份恢复</title>
</head><body>
<%
IF KEY<>0 then
	Call Error2("你的权限不足！")
end if

dim action,currf,backf,backfy,objfso
' db="../#74hucn.mdb"
action=Request.QueryString("action")
On error resume next

If Not ifObjInstalled("Scripting.FileSystemObject") Then
	Response.Write "你的服务器不支持 FSO(Scripting.FileSystemObject)! 不能使用本功能"
Else
	If action="back" Then
		currf=request.form("currf")
		if currf="" then
			Call Error2("原数据库地址错误")
		else
			currf=server.mappath(currf)
		end if
		backf=request.form("backf")
		if backf="" then
			Call Error2("备份数据目录错误")
		else
			backf=server.mappath(backf)
		end if
		backfy=request.form("backfy")
		if backfy="" then Call Error2("备份数据名称错误")
		Set objfso = Server.CreateObject("Scripting.FileSystemObject")
		if err then
			err.clear
			Call Error2("不能建立fso对象，请确保你的空间支持fso:！")
		end if
		if objfso.Folderexists(backf) = false then
			objfso.CreateFolder(backf)
		end if
		objfso.copyfile currf,backf& "\"& backfy
		set objfso=Nothing
		w "备份数据库成功"
	elseIf action="ys" Then
		currf=request.form("currf")
		if currf="" then
			Call Error2("原数据库地址错误")
		else
			currf = server.mappath(currf)
		end if
		backf=request.form("backf")
		if backf="" then
			Call Error2("压缩数据目录错误")
		else
			backf=server.mappath(backf)
		end if
		If right(backf,1)<>"\" Then backf = backf & "\"
		Set objfso = Server.CreateObject("Scripting.FileSystemObject")
		if objfso.Folderexists(backf) = false then
			Call Error2("压缩数据目录错误")
		end if
		dim ys
		ys=request.form("ys")
		Const JET_3X = 4
		if err then
			err.clear
			Call Error2("不能建立fso对象，请确保你的空间支持fso:！")
		end if

		if objfso.fileexists(currf) then
			dim Engine,tmpdb
			Set Engine = CreateObject("JRO.JetEngine")
			dbTemp1= backf &"temp.mdb"
			dbTemp2= backf &"temp1.mdb"
			objfso.CopyFile currf,dbTemp1
			If ys = "1" Then
				Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbTemp1, _
				"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbTemp2 &";" _
				& "Jet OLEDB:Engine Type=" & JET_3X
			Else
				Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbTemp1, _
				"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbTemp2
			End If
			objfso.CopyFile dbTemp2,currf
			' if err then
				' err.clear
				' Call Error2("错误:操作失败！数据库引擎加载出错")'err.description
			' end if
			objfso.DeleteFile(dbTemp1)
			objfso.DeleteFile(dbTemp2)
			Set Engine = nothing
			w "压缩数据库成功"
		Else
			Call Error2("错误:找不到数据库文件！")
		End If
		Set objfso = nothing
	elseIf action="reload" then
		currf=request.form("currf")
		if currf="" then
			Call Error2("原数据库地址错误")
		else
			currf=server.mappath(currf)
		End If
		backf=request.form("backf")
		if backf="" then
			Call Error2("备份数据库地址错误")
		else
			backf=server.mappath(backf)
		end if
		Set objfso = Server.CreateObject("Scripting.FileSystemObject")
		if err then
			err.clear
			Call Error2("不能建立fso对象，请确保你的空间支持fso:！")
		end if
		if objfso.fileexists(backf) then
			objfso.copyfile backf,currf
			w "恢复数据库成功"
		else
			Call Error2("错误:找不到数据库文件！")
		end if
		set objfso=Nothing
	else
		dim dbpath,dbsize
		dbpath = server.mappath(db)
		dbsize=0
		set fso=CreateObject("Scripting.FileSystemObject")
		if fso.FileExists(dbpath) then
			set f = fso.GetFile(dbpath)
			dbsize=f.size
			set f = nothing
		end if
		set fso=nothing
%>
数据库大小:<%=forFileSize(dbsize)%>
<form name="form1" method="POST" action="bak.asp?action=back&sid=<%=sid%>">
<p>备份数据库</p>
<input type="text" name="currf" size="20" value="<%=db%>" readonly /><br/>
备份数据目录：<br/>
<input type="text" name="backf" size="20" value="74huback" readonly /><br/>
数据库名称：<br/>
<input type="text" name="backfy" size="20" value="backup.mdb"/><br/>
<input type="submit" name="Submit" value="备份" />
</form>
-----------
<form name="form1" method="POST" action="bak.asp?action=reload&sid=<%=sid%>">
<p>恢复数据库</p>
当前数据库路径：<br/>
<input type="text" name="currf" size="20" value="<%=db%>" readonly /><br/>
备份数据库路径：<br/>
<input type="text" name="backf" size="20" value="74huback/backup.mdb"/><br/>
<input type="submit" name="Submit" value="恢复" />
</form>
-----------
<form name="form1" method="POST" action="bak.asp?action=ys&sid=<%=sid%>">
<p>压缩数据库</p>
当前数据库路径：<br/>
<input type="text" name="currf" size="20" value="<%=db%>" readonly /><br/>
<input type="hidden" name="backf" value="74huback"/><br/>
<!--数据库引擎：<select name="ys">
<option value="0">Jet Engine</option>
<option value="1">Jet 4 Engine</option>
</select><br/>-->
<input type="hidden" name="ys" value="0"/>
<input type="submit" name="Submit" value="压缩" />
</form>
<font color="red">温馨提示：<br/>1、除非明白操作，否则不要更改以上项<br/>2、不要频繁使用，尽量在访问人少时操作</font>
<%
	end if
end if
%>
<br/><a href="74hu/index.asp?sid=<%=sid%>">[站长工具]</a>
<%call rootLast2%>